<template>
  <au-context-menu ref="auContextMenu" @on-click="onClick" :data="objData"></au-context-menu>
</template>

<script>
import AuContextMenu from "@/components/comm/auContextMenu";
import {ipcRenderer,clipboard} from "electron";
export default {
name: "auImageRightMenu",
  components: {AuContextMenu},
  data(){
    return {
      eventInfo:null
    }
  },
  props:{
    imageBase64:{
      default: null,
      type:String
    },
    scale:{
      type:Number,
      default:100
    }
  },
  computed:{
    objData(){
      return [{
        title:"复制坐标",
        id:201
      },{
        title:"复制颜色",
        id:202
      },'-',{
        title:"色彩对比",
        id:203,
        list:[
          {
            title:"加入点1",
            id:20301
          },{
            title:"加入点2",
            id:20302
          },{
            title:"加入点3",
            id:20303
          },{
            title:"加入点4",
            id:20304
          },{
            title:"加入点5",
            id:20305
          },{
            title:"加入点6",
            id:20306
          }
        ]
      }];
    },
    pointLayer(){
      let e=this.eventInfo;
      if(e){
        let x=e.layerX/this.scale*100;
        let y=e.layerY/this.scale*100;
        return {
          x,y
        }
      }
      return {
        x:0,
        y:0
      };
    }
  },
  methods:{
    onClick201(it,index,itemIndex){
      let point=this.pointLayer;
      clipboard.writeText(`${point.x},${point.y}`);
      this.$message.success("复制成功");
    },
    onClick202(it,index,itemIndex){
      console.log(this.pointLayer)
      ipcRenderer.invoke("image-point-color",{
        image:this.imageBase64,
        info:{
          ...this.pointLayer
        },
      }).then(res=>{
        if(res){
          console.log(res)
        }
      })
    },
    onClick(it,index,itemIndex){
      console.log(it.id)
      if(it.id && this["onClick"+it.id]){
        this["onClick"+it.id](...arguments)
      }
    },
    show(e){
      this.eventInfo=e;
      this.$refs.auContextMenu.show(e);
    },
    hide(){
      this.$refs.auContextMenu.hide();
    }
  }
}
</script>

<style scoped>

</style>
